using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPages_Default : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptInclude(Page.GetType(), "SiteScript", WebTool.getWebRoot() + "/Scripts/site.js");

        btnLoginFormSubmit.Click += new EventHandler(btnLoginFormSubmit_Click);
        btnLogout.Click += new EventHandler(btnLogout_Click);
        if (SessionHelper<int>.existsVar("UserId"))
        {
            if (SessionHelper<int>.getVar("UserId") != null)
            {
                divHeaderLoginBox.Visible = false;
                divHeaderLoggedBox.Visible = true;
            }
        }
        else
        {
            divHeaderLoginBox.Visible = true;
            divHeaderLoggedBox.Visible = false;
        }
    }

    void btnLogout_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        divHeaderLoginBox.Visible = true;
        divHeaderLoggedBox.Visible = false;
    }

    void btnLoginFormSubmit_Click(object sender, EventArgs e)
    {
        Login l = new Login();
        if (!tbLoginFormPassword.Text.Equals("") && !tbLoginFormUserName.Text.Equals(""))
            l.login(tbLoginFormUserName.Text, tbLoginFormPassword.Text);
        
        if (SessionHelper<int>.existsVar("UserId"))
        {
            if (SessionHelper<int>.getVar("UserId") != null)
            {
                divHeaderLoginBox.Visible = false;
                divHeaderLoggedBox.Visible = true;
            }
        }
    }
}
